package com.lin.controller;


import com.lin.Demo.JSON;
import com.lin.Demo.JSONS;
import com.lin.domain.Article;
import com.lin.domain.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/article")
public  class TestController1 {
    @RequestMapping(value="/getArticle", method = RequestMethod.GET)
    @JSON(type = Article.class, filter="createTime")
    public Article get() {
        //获取数据
        Article article=getArticle();
        //返回结果
        return article;
    }

    @RequestMapping(value="/list", method = RequestMethod.GET)
    @JSON(type = Article.class  , include="id,title")
    public List<Article> findAll() {
        List<Article> articleList = getArticleList();
        return articleList;
    }

    @RequestMapping(value="/lists", method = RequestMethod.GET)
    @JSONS({@JSON(type = Article.class  , include="id,title"),@JSON(type = Article.class  , filter="title")})
    public List<Article> findAlls() {
        List<Article> articleList = getArticleList();
        return articleList;
    }
    private  Article getArticle(){
        Article article= new Article();
        article.setId("123");
        article.setContent("cont");
        article.setTitle("标题");
        article.setCreateTime("2017年2月26日20:53:00");
        return  article;
    }

    private List<Article>  getArticleList(){
        Article article= new Article();
        article.setId("123");
        article.setContent("cont");
        article.setTitle("标题");
        article.setCreateTime("2017年2月26日20:53:00");
        List<Article> articleList = new ArrayList<>();
        articleList.add(article);
        articleList.add(article);
        articleList.add(article);
        articleList.add(article);
        return  articleList;
    }
}
